SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Setting table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Find
(

	@SearchUsingOR bit   = null ,

	@SettingName nvarchar (50)  = null ,

	@SettingValue nvarchar (50)  = null ,

	@DataType nchar (10)  = null ,

	@Description nchar (10)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
	, [DataType]
	, [Description]
    FROM
	[dbo].[Setting]
    WHERE 
	 ([SettingName] = @SettingName OR @SettingName IS NULL)
	AND ([SettingValue] = @SettingValue OR @SettingValue IS NULL)
	AND ([DataType] = @DataType OR @DataType IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
	, [DataType]
	, [Description]
    FROM
	[dbo].[Setting]
    WHERE 
	 ([SettingName] = @SettingName AND @SettingName is not null)
	OR ([SettingValue] = @SettingValue AND @SettingValue is not null)
	OR ([DataType] = @DataType AND @DataType is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
